function getDateAgo(dateStr) {
/**
 * @功能
 * 将传入的时间戳(毫秒)与当前时间戳进行比较，转换成几秒前、几分钟前、几小时前、几天前的形式。
 * @param 必填 {dataStr} DateString|Number
 * @例子
 * 字符串类型:getDateAgo('2019-05-04 14:23:19') getDateAgo('2019-05-04')
 * 整型:1558680958000必须是毫秒级 getDateAgo(1373241600000)
 */
    var tf = function (i) { return (i < 10 ? '0' : '') + i };
    var getDateTimeStamp = function (t) { 
        if (typeof t === 'string') {
            return new Date(t.replace(/-/gi, "/")).getTime()
        }
        return t
    };
    var publishTime = getDateTimeStamp(dateStr),
        d_seconds,
        d_minutes,
        d_hours,
        d_days,
        timeNow = new Date().getTime(),
        d,
        date = new Date(publishTime),
        Y = date.getFullYear(),
        M = date.getMonth() + 1,
        D = date.getDate(),
        H = date.getHours(),
        m = date.getMinutes(),
        s = date.getSeconds();
        //小于10的在前面补0

    M=tf(M)
    D=tf(D)
    H=tf(H)
    m=tf(m)
    s=tf(s)

    d = (timeNow - publishTime)/1000;
    d_days = parseInt(d/86400);
    d_hours = parseInt(d/3600);
    d_minutes = parseInt(d/60);
    d_seconds = parseInt(d);

    if(d_days > 0 && d_days < 3){
        return d_days + '天前';
    }else if(d_days <= 0 && d_hours > 0){
        return d_hours + '小时前';
    }else if(d_hours <= 0 && d_minutes > 0){
        return d_minutes + '分钟前';
    }else if (d_seconds < 60) {
        if (d_seconds <= 30) {
            return '刚刚发表';
        }else {
            return d_seconds + '秒前';
        }
    }else if (d_days >= 3 && d_days < 30){
        return M + '-' + D + '&nbsp;' + H + ':' + m;
    }else if (d_days >= 30) {
        return Y + '-' + M + '-' + D + '&nbsp;' + H + ':' + m;
    }
}    